package com.woniu.punishcomplaintnotice.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniu.common.entity.Adopt;
import com.woniu.common.entity.AdoptApply;
import com.woniu.common.entity.PageResult;
import com.woniu.punishcomplaintnotice.mapper.AdoptMapper;
import com.woniu.punishcomplaintnotice.service.AdoptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdoptServiceImpl implements AdoptService {
    @Autowired
    AdoptMapper adoptMapper;

    // 封装分页信息
    public <T> PageResult<T> getResult(int page, int size, Page<T> pageHelper,List<T> data) {
        // 获取分页信息
        PageResult<T> pageResult = new PageResult<>();
        // 当前页
        pageResult.setCurrentPage(page);
        // 每一页大小
        pageResult.setSize(size);
        // 总条数
        pageResult.setTotal(pageHelper.getTotal());
        // 总页数
        pageResult.setTotalPage(pageHelper.getPages());
        //查询出的数据
        pageResult.setDatas(data);

        return pageResult;
    }

    @Override
    public void insertInfo(Adopt adopt) {
        adoptMapper.insertDog(adopt);
    }

    //修改领养状态
    @Override
    public boolean updateStatus(Integer id) {
        return adoptMapper.updateStatus(id);
    }

    //查询领养信息
    @Override
    public PageResult<Adopt> findAllAdopt(Integer page, Integer size) {
        Page<Adopt> pagestart = PageHelper.startPage(page, size);

        List<Adopt> adopts = adoptMapper.findAllAdopt();

        return getResult(page,size,pagestart,adopts);

    }

    //领养申请
    @Override
    public boolean addAdoptApply(AdoptApply adoptApply) {
        return adoptMapper.addAdoptApply(adoptApply);
    }



}
